package cn.fl.riskctrl.corp.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import cmm.comm.facade.upload.condition.SysUlDatCfgQueryCondition;
import cmm.comm.facade.upload.condition.SysUlFilesRecQueryCondition;
import cmm.comm.facade.upload.constant.UploadConstant;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.project.constant.PrjBscInfoConstant;
import cn.fl.project.vo.PrjLnkCompVO;
import cn.fl.system.constant.SysLogConstant;
import cn.fl.system.service.ISysUlDatCfgService;
import cn.fl.system.service.ISysUlFilesRecService;
import cn.fl.system.vo.SysUlDatCfgDtlVO;
import cn.fl.system.vo.SysUlDatCfgVO;
import cn.fl.system.vo.SysUlFilesRecVO;
import fl.constant.facade.framework.constant.FlowConstant;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;

import cn.fl.riskctrl.corp.service.IRcWlTpMgtService;
import cn.fl.riskctrl.corp.vo.RcWlTpMgtVO;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import rc.constant.facade.constant.RcCorpBaseInfoConstants;
import rc.corpbaseinfo.facade.corpbaseinfo.condition.RcWlTpMgtQC;

/**
 * @Description: RC_WL_TP_MGT（物流小秘税开管理） 控制层
 */
@Controller
@RequestMapping("/corp/rcwltpmgt")
public class RcWlTpMgtController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(RcWlTpMgtController.class);

	/**
	 * RcWlTpMgt 服务层BEAN
	 */
	@Autowired
	private IRcWlTpMgtService rcWlTpMgtService;
    @Autowired
    private ISysUlDatCfgService sysUlDatCfgService;//上传资料配置表
    @Autowired
    private ISysUlFilesRecService sysUlFilesRecService;//文件上传记录表

	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toListPage", "加载列表页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
        String status = request.getParameter("status");
        ModelAndView view = new ModelAndView("riskctrl/corp/rcWlTpMgtList");
        view.addObject("status", status);
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toListPage", "加载列表页面.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 到修改页面
	 */
	@RequestMapping(value = "/toModifyPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toAddPage", "加载修改页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		String id = request.getParameter("id");

        SysUlDatCfgQueryCondition qc = new SysUlDatCfgQueryCondition();
        // 前置征信物流小秘税开管理信审补录资料配置信息
        List<String> codeList = new ArrayList<>();
        codeList.add(RcCorpBaseInfoConstants.CFG_CD);
        qc.setCfgCdList(codeList);

        String orgCd = PrjBscInfoConstant.CODE_PRJ_FILE_DEF_ORG;
        qc.setOrgCd(orgCd);
        qc.setSysCd(RcCorpBaseInfoConstants.SYS_CD);
        List<SysUlDatCfgVO> list = sysUlDatCfgService.searchList(qc);
        SysUlDatCfgVO cfg = null;
        if (CollectionUtils.isNotEmpty(list)) {
            cfg = list.get(0);
        }
        List<SysUlDatCfgDtlVO> dtlList = cfg.getSysUlDatCfgDtlVOList();
        List<SysUlFilesRecVO> dtlFileList = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(dtlList)) {
            for (SysUlDatCfgDtlVO sysUlDatCfgDtlVO : dtlList) {
                SysUlFilesRecQueryCondition ulFileQc = new SysUlFilesRecQueryCondition();
                ulFileQc.setCfgCd(qc.getCfgCdList().get(0));
                ulFileQc.setSysCd(qc.getSysCd());
                ulFileQc.setOrgCd(orgCd);
                ulFileQc.setPkId(id);
                ulFileQc.setCfgDtlCd(sysUlDatCfgDtlVO.getCfgDtlCd());
                ulFileQc.setTabNm("RC_WL_TP_MGT");
                List<SysUlFilesRecVO> fileList = sysUlFilesRecService.searchList(ulFileQc);
                if (CollectionUtils.isNotEmpty(fileList)) {
                    for (SysUlFilesRecVO sysUlFilesRecVO : fileList) {
                        sysUlFilesRecVO.setSysCd(sysUlDatCfgDtlVO.getSysCd());
                        sysUlFilesRecVO.setCfgCd(qc.getCfgCdList().get(0));
                        sysUlFilesRecVO.setOrgCd(sysUlDatCfgDtlVO.getOrgCd());
                        sysUlFilesRecVO.setCfgDtlCd(sysUlDatCfgDtlVO .getCfgDtlCd());
                        sysUlFilesRecVO.setDatNm(sysUlDatCfgDtlVO.getDatNm());
                        dtlFileList.add(sysUlFilesRecVO);
                    }
                } else {
                    SysUlFilesRecVO filesRecVO = new SysUlFilesRecVO();
                    filesRecVO.setSysCd(sysUlDatCfgDtlVO.getSysCd());
                    filesRecVO.setCfgCd(qc.getCfgCdList().get(0));
                    filesRecVO.setOrgCd(sysUlDatCfgDtlVO.getOrgCd());
                    filesRecVO.setCfgDtlCd(sysUlDatCfgDtlVO.getCfgDtlCd());
                    filesRecVO.setDatNm(sysUlDatCfgDtlVO.getDatNm());
                    dtlFileList.add(filesRecVO);
                }
            }
        }

        String serverPath = PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_SERVER_PATH);// 服务地址
        String customerPah = PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_COSTOMER_PATH);
        String headPic = PropertiesCacheUtils
                .getProperty(fl.constant.facade.framework.constant.UploadConstant.DEFAULT_NO_PIC);

		ModelAndView view = new ModelAndView("riskctrl/corp/rcWlTpMgtAdd");
        RcWlTpMgtVO rcWlTpMgtVO = this.rcWlTpMgtService.selectById(Long.valueOf(id));
        if (rcWlTpMgtVO != null) {
            SysUlFilesRecQueryCondition condition = new SysUlFilesRecQueryCondition();
            condition.setPkId(rcWlTpMgtVO.getRcCstCorpBscInfoId().toString());
            condition.setTabNm(RcCorpBaseInfoConstants.MASTER_TABLE_NAME);
            condition.setSysCd(CurrentThreadContext.getCurrentSysCd());//系统代码-必须条件
            List<SysUlFilesRecVO> sysUlFilesRecList = this.sysUlFilesRecService.searchList(condition);
            BaseLogUtils.info(logger, "toAddPage", "查询到的附件：" + JSONObject.toJSONString(sysUlFilesRecList), CurrentThreadContext.getCurrentUserName());
            for (SysUlFilesRecVO sysUlFilesRecVO : sysUlFilesRecList) {
                if ("13".equals(sysUlFilesRecVO.getCfgDtlCd())) {
                    view.addObject("sysUlFilesRecVO1", sysUlFilesRecVO);
                } else if ("14".equals(sysUlFilesRecVO.getCfgDtlCd())) {
                    view.addObject("sysUlFilesRecVO2", sysUlFilesRecVO);
                } else if ("15".equals(sysUlFilesRecVO.getCfgDtlCd())) {
                    view.addObject("sysUlFilesRecVO3", sysUlFilesRecVO);
                }
            }
        }

        view.addObject("rcWlTpMgtVO", rcWlTpMgtVO);
        view.addObject("dtlList", dtlFileList);
        view.addObject("defImg", serverPath + customerPah + headPic);
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toAddPage", "加载修改.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		return view;
	}

    /**
     * 到添加照片列表页面
     */
    @RequestMapping(value = "/addInvestImgPage.do", method = {
            RequestMethod.GET, RequestMethod.POST })
    public ModelAndView addSurveyPage(HttpServletRequest request,
                                      HttpServletResponse response) {
        logger.info("到添加考察照片列表页面.");
        String rcWlTpMgtId = request.getParameter("rcWlTpMgtId");
        String sysCd = request.getParameter("sysCd");
        String orgCd = request.getParameter("orgCd");
        String cfgCd = request.getParameter("cfgCd");
        String cfgDtlCd = request.getParameter("cfgDtlCd");
        ModelAndView view = new ModelAndView(
                "riskctrl/corp/addInvestImgPage");
        view.addObject("rcWlTpMgtId", rcWlTpMgtId);
        view.addObject("sysCd", sysCd);
        view.addObject("orgCd", orgCd);
        view.addObject("cfgCd", cfgCd);
        view.addObject("cfgDtlCd", cfgDtlCd);
        return view;
    }

    @RequestMapping(value = "/addPhoto.do", method = { RequestMethod.POST })
    @ResponseBody
    public Object addPhoto(HttpServletRequest request,
                                  HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,
                SysLogConstant.LOG_CMM_ADD_SUCC);
        PrjLnkCompVO entity = null;
        String rcWlTpMgtId = request.getParameter("rcWlTpMgtId");
        String fileNm = request.getParameter("fileNm");
        String filePath = request.getParameter("filePath");
        String sysCd = request.getParameter("sysCd");
        String orgCd = request.getParameter("orgCd");
        String cfgCd = request.getParameter("cfgCd");
        String cfgDtlCd = request.getParameter("cfgDtlCd");
        Long id = null;
        try {
            SysUlFilesRecVO fileRec = new SysUlFilesRecVO();
            if (StringUtils.isNotBlank(rcWlTpMgtId)) {
                fileRec.setPkId(rcWlTpMgtId);
            }
            SysUlFilesRecQueryCondition fileQc = new SysUlFilesRecQueryCondition();
            fileQc.setCfgCd(cfgCd);
            fileQc.setPkId(rcWlTpMgtId);
            fileQc.setTabNm("RC_WL_TP_MGT");
            fileQc.setOrgCd(orgCd);
            fileQc.setSysCd(sysCd);
            fileQc.setCfgDtlCd(cfgDtlCd);
            // this.sysUlFilesRecService.removeByCondition(fileQc);
            fileRec.setFileNm(fileNm);
            fileRec.setFilePath(filePath);
            fileRec.setSysCd(sysCd);
            fileRec.setOrgCd(orgCd);
            fileRec.setCfgCd(cfgCd);
            fileRec.setCfgDtlCd(cfgDtlCd);
            fileRec.setTabNm("RC_WL_TP_MGT");
            fileRec.setCrtTm(new Date());
            fileRec.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
            fileRec.setMdfTm(new Date());
            fileRec.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
            fileRec.setIsDel(BaseConstant.IS_YESNO_NO);
            // id = this.sysUlFilesRecService.add(fileRec);
            id = this.rcWlTpMgtService.addFileRec(fileQc, fileRec);
            // 查询保存成功的数据
            SysUlFilesRecVO filesRecVO = this.sysUlFilesRecService
                    .selectById(id);
            result.setData(filesRecVO);

            BaseLogUtils.info(logger, "add", "新增数据.[id=" + id + "] DATA:"
                            + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(entity)
                            + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(entity)
                            + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }
	
	/**
	 * 到详情页面
	 */
	@RequestMapping(value = "/toDetailPage.do", method = { RequestMethod.GET})
	public ModelAndView toDetailPage(HttpServletRequest request, HttpServletResponse response) {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toDetailPage", "加载例子详细页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		String id = request.getParameter("id");
        SysUlDatCfgQueryCondition qc = new SysUlDatCfgQueryCondition();
        // 前置征信物流小秘税开记录查看信审补录资料配置信息
        List<String> codeList = new ArrayList<>();
        codeList.add(RcCorpBaseInfoConstants.CFG_CD);
        qc.setCfgCdList(codeList);
        String orgCd = PrjBscInfoConstant.CODE_PRJ_FILE_DEF_ORG;
        qc.setOrgCd(orgCd);
        qc.setSysCd(RcCorpBaseInfoConstants.SYS_CD);
        List<SysUlDatCfgVO> list = sysUlDatCfgService.searchList(qc);
        SysUlDatCfgVO cfg = null;
        if (CollectionUtils.isNotEmpty(list)) {
            cfg = list.get(0);
        }
        List<SysUlDatCfgDtlVO> dtlList = cfg.getSysUlDatCfgDtlVOList();
        List<SysUlFilesRecVO> dtlFileList = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(dtlList)) {
            for (SysUlDatCfgDtlVO sysUlDatCfgDtlVO : dtlList) {
                SysUlFilesRecQueryCondition ulFileQc = new SysUlFilesRecQueryCondition();
                ulFileQc.setCfgCd(qc.getCfgCdList().get(0));
                ulFileQc.setSysCd(qc.getSysCd());
                ulFileQc.setPkId(id);
                ulFileQc.setOrgCd(orgCd);
                ulFileQc.setCfgDtlCd(sysUlDatCfgDtlVO.getCfgDtlCd());
                ulFileQc.setTabNm("RC_WL_TP_MGT");
                List<SysUlFilesRecVO> fileList = sysUlFilesRecService.searchList(ulFileQc);
                if (CollectionUtils.isNotEmpty(fileList)) {
                    for (SysUlFilesRecVO sysUlFilesRecVO : fileList) {
                        sysUlFilesRecVO.setCfgCd(qc.getCfgCdList().get(0));
                        sysUlFilesRecVO.setSysCd(sysUlDatCfgDtlVO.getSysCd());
                        sysUlFilesRecVO.setOrgCd(sysUlDatCfgDtlVO.getOrgCd());
                        sysUlFilesRecVO.setCfgDtlCd(sysUlDatCfgDtlVO .getCfgDtlCd());
                        sysUlFilesRecVO.setDatNm(sysUlDatCfgDtlVO.getDatNm());
                        dtlFileList.add(sysUlFilesRecVO);
                    }
                } else {
                    SysUlFilesRecVO filesRecVO = new SysUlFilesRecVO();
                    filesRecVO.setCfgCd(qc.getCfgCdList().get(0));
                    filesRecVO.setOrgCd(sysUlDatCfgDtlVO.getOrgCd());
                    filesRecVO.setSysCd(sysUlDatCfgDtlVO.getSysCd());
                    filesRecVO.setCfgDtlCd(sysUlDatCfgDtlVO.getCfgDtlCd());
                    filesRecVO.setDatNm(sysUlDatCfgDtlVO.getDatNm());
                    dtlFileList.add(filesRecVO);
                }
            }
        }

        String serverPath = PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_SERVER_PATH);// 服务地址
        String customerPah = PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_COSTOMER_PATH);
        String headPic = PropertiesCacheUtils
                .getProperty(fl.constant.facade.framework.constant.UploadConstant.DEFAULT_NO_PIC);

        RcWlTpMgtVO rcWlTpMgtVO = this.rcWlTpMgtService.selectById(Long.valueOf(id));

        ModelAndView view = new ModelAndView("riskctrl/corp/rcWlTpMgtDetail");
        view.addObject("rcWlTpMgtVO", rcWlTpMgtVO);
        view.addObject("dtlList", dtlFileList);
        view.addObject("defImg", serverPath + customerPah + headPic);

		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toDetailPage", " 加载例子详细页面.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "initList", "加载列表页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String corpCstNm = request.getParameter("corpCstNm");
		String corpCertTypCd = request.getParameter("corpCertTypCd");
		String corpCertNo = request.getParameter("corpCertNo");
		String operationNm = request.getParameter("operationNm");
		String operationCd = request.getParameter("operationCd");
		String stDt = request.getParameter("stDt");
		String endDt = request.getParameter("endDt");
		String status = request.getParameter("status");

		RcWlTpMgtQC qc = new RcWlTpMgtQC();
		if (StringUtils.isNotEmpty(corpCstNm)) {
            qc.setCorpCstNm(corpCstNm);
		}
		if (StringUtils.isNotEmpty(corpCertTypCd)) {
            qc.setCorpCertTypCd(corpCertTypCd);
		}
		if (StringUtils.isNotEmpty(corpCertNo)) {
            qc.setCorpCertNo(corpCertNo);
		}
		if (StringUtils.isNotEmpty(operationNm)) {
            qc.setOperationNm(operationNm);
		}
		if (StringUtils.isNotEmpty(operationCd)) {
            qc.setOperationCd(operationCd);
		}
        if (StringUtils.isNotEmpty(stDt)) {
            Date start = DateUtils.formatStringToDate(stDt,DateUtils.YYYY_MM_DD);
            qc.setStDt(start);
        }
        if (StringUtils.isNotEmpty(endDt)) {
            Date end = DateUtils.formatStringToDate(endDt,DateUtils.YYYY_MM_DD);
            qc.setEndDt(end);
        }
		if (StringUtils.isNotEmpty(status)) {
            qc.setStatus(status);
		}

		Pager pager = this.rcWlTpMgtService.searchListPage(Integer.valueOf(pageSize), Integer.valueOf(currentPage), qc);
		List<RcWlTpMgtVO> list = (List<RcWlTpMgtVO>) pager.getResultList();
		ListPageVO<RcWlTpMgtVO> listPage = new ListPageVO<RcWlTpMgtVO>(list, pager.getTotalCount());
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "initList", "加载列表页面.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}
	
	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "add", "新增对象.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		String name = request.getParameter("name");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");
		RcWlTpMgtVO entity;
		try {
			entity = new RcWlTpMgtVO();
			//TODO ADD PARAM
			Long id = this.rcWlTpMgtService.add(entity);
			result.setData(id);
			BaseLogUtils.info(logger, "add", "新增数据.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "add", "新增对象失败,name["+name+"].", CurrentThreadContext.getCurrentUserName(), ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.error(logger, "add", "新增对象失败,name["+name+"].", CurrentThreadContext.getCurrentUserName(), ex);
		}
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "add", "新增对象.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		
		return result;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "modify", "修改对象.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		String id = request.getParameter("id");
		String invoiTotalReve1to12 = request.getParameter("invoiTotalReve1to12");
        invoiTotalReve1to12 = invoiTotalReve1to12.replaceAll(",", "");
		String invoiTotalReve1to24 = request.getParameter("invoiTotalReve1to24");
        invoiTotalReve1to24 = invoiTotalReve1to24.replaceAll(",", "");
		String enterpriseLevel = request.getParameter("enterpriseLevel");
        String rem = request.getParameter("rem");
        String isValid = request.getParameter("isValid");
        String rcCstCorpBscInfoId = request.getParameter("rcCstCorpBscInfoId");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "修改成功!");
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("数据不存在!");
			BaseLogUtils.info(logger, "modify", "修改数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		if (StringUtils.isNotEmpty(invoiTotalReve1to12) && !NumberUtils.isNumber(invoiTotalReve1to12)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("第1-12月增值税开票总收入必须是数字!");
            BaseLogUtils.info(logger, "modify", "第1-12月增值税开票总收入必须是数字", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        if (StringUtils.isNotEmpty(invoiTotalReve1to24) && !NumberUtils.isNumber(invoiTotalReve1to24)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("第13-24月增值税开票总收入必须是数字!");
            BaseLogUtils.info(logger, "modify", "第13-24月增值税开票总收入必须是数字", CurrentThreadContext.getCurrentUserName());
            return result;
        }
		RcWlTpMgtVO entity = null;
		try {
			entity = new RcWlTpMgtVO();
			entity.setId(Long.valueOf(id));
			entity.setIsValid(Integer.valueOf(isValid));
			entity.setRcCstCorpBscInfoId(Long.valueOf(rcCstCorpBscInfoId));
            entity.setInvoiTotalReve1to12(invoiTotalReve1to12);
            entity.setInvoiTotalReve1to24(invoiTotalReve1to24);
            if (NumberUtils.isNumber(enterpriseLevel)) {
                entity.setEnterpriseLevel(Integer.valueOf(enterpriseLevel));
            }
            entity.setRem(rem);
            String audPass = PropertiesCacheUtils.getProperty(FlowConstant.FLOW_CHECK_STATE_PASS);
            entity.setAudStsCd(audPass);
            entity.setOperationCompletionTm(new Date());
			boolean success = this.rcWlTpMgtService.modify(entity);
			if (!success) {
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("修改失败!");
				BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			}
			BaseLogUtils.info(logger, "modify", "修改成功.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modify", "修改对象失败,id["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.error(logger, "modify", "修改对象失败,id["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		}
		
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "modify", "修改对象.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());

		return result;
	}

	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "getById", "根据主键获取对象.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("主键不能为空!");
			BaseLogUtils.error(logger, "getById", "获取数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		try {
			RcWlTpMgtVO vo = this.rcWlTpMgtService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("数据不存在!");
				BaseLogUtils.info(logger, "getById", "获取数据,数据不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			}
			result.setData(vo);
			BaseLogUtils.info(logger, "getById", "获取数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getById", "根据主键获取对象失败,主键["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.error(logger, "getById", "根据主键获取对象失败,主键["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		}
		
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "getById", "根据主键获取对象.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());

		return result;
	}

	/**
	 * 获取三方数据
	 * @methodName authThreeData
	 * @Author: LBC
	 * @createDate: 2020/12/7
	 * @version: V1.0.0
	 * @Param: [request]
	 * @Return: java.lang.Object
	 * @updateRemark [序号][YYYY-MM-DD] [更改人姓名][变更描述]
	 */
    @RequestMapping(value = "/authThreeData.do", method = { RequestMethod.POST })
    @ResponseBody
    public Object authThreeData(HttpServletRequest request) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "authThreeData", "获取三方数据.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());

        String rcWlTpMgtId = request.getParameter("rcWlTpMgtId");
        String rcCstCorpBscInfoId = request.getParameter("rcCstCorpBscInfoId");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "获取三方数据成功!");
        if(StringUtils.isEmpty(rcCstCorpBscInfoId)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("数据不存在!");
            BaseLogUtils.info(logger, "authThreeData", "获取三方数据,参数为空.", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        try {
            result = this.rcWlTpMgtService.authThreeData(rcCstCorpBscInfoId, rcWlTpMgtId);
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "authThreeData", "获取三方数据失败,rcCstCorpBscInfoId["+rcCstCorpBscInfoId+"].", CurrentThreadContext.getCurrentUserName(),ex);
        }catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("系统错误,请联系管理员!");
            BaseLogUtils.error(logger, "authThreeData", "获取三方数据失败,rcCstCorpBscInfoId["+rcCstCorpBscInfoId+"].", CurrentThreadContext.getCurrentUserName(),ex);
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "authThreeData", "获取三方数据.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());

        return result;
    }
}

